var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$ResourceLoader = require("ResourceLoader");
var i = cc__importDefault($1$ResourceLoader);
var def_RopeSegmentManager = function () {
  function _ctor() {
    this.segmentPools = new Map();
  }
  _ctor.getInstance = function () {
    // 检查实例是否已存在，如果不存在，则创建一个新实例
    if (!this.instance) {
      this.instance = new _ctor(); // 创建新实例
    }
    return this.instance; // 返回当前实例
  };
  _ctor.prototype.getSegment = function (t) {
    // 检查是否已经存在对应类型的段池，如果不存在则创建一个新池
    if (!this.segmentPools.has(t)) {
      this.segmentPools.set(t, new cc.NodePool());
    }

    // 获取对应类型的段池
    var nodePool = this.segmentPools.get(t);

    // 如果段池为空，则创建新的节点和Sprite组件
    if (nodePool.size() <= 0) {
      var ropeSegment = new cc.Node("RopeSegment"); // 创建新节点
      var spriteComponent = ropeSegment.addComponent(cc.Sprite); // 添加Sprite组件

      // 加载指定名称的SpriteFrame
      i.default.getInstance().load("Feibiao", "rope/segment/" + (t + 1), cc.SpriteFrame).then(function (spriteFrame) {
        spriteComponent.spriteFrame = spriteFrame; // 设置SpriteFrame
      });

      // 将新创建的节点放入段池
      nodePool.put(ropeSegment);
    }

    // 从段池中获取节点
    return nodePool.get();
  };
  _ctor.prototype.putSegment = function (t, e) {
    var poolGet = this.segmentPools.get(t);
    poolGet && poolGet.put(e);
  };
  _ctor.prototype.clearPool = function (t) {
    var segment = this.segmentPools.get(t);
    if (segment) {
      segment.clear();
      this.segmentPools.delete(t);
    }
  };
  _ctor.prototype.clearAllPools = function () {
    this.segmentPools.forEach(function (_pool) {
      return _pool.clear();
    });
    this.segmentPools.clear();
  };
  _ctor.instance = null;
  return _ctor;
}();
exports.default = def_RopeSegmentManager;